local Fun = {}
local uis = game:GetService("UserInputService")
local tweenService = game:GetService("TweenService")
local runService = game:GetService("RunService")
local lighting = game:GetService("Lighting")
local players = game:GetService("Players")
local lp = players.LocalPlayer
local pg = lp:WaitForChild("PlayerGui")

-- 动画配置（统一参数确保风格一致）
local ANIM_SPEED = 0.22
local EASE_IN_OUT = Enum.EasingStyle.Quad
local EASE_OUT = Enum.EasingStyle.Sine
local EASE_IN = Enum.EasingStyle.Sine

-- 基础模糊效果
local blur = Instance.new("BlurEffect")
blur.Name = "UIBlur"
blur.Size = 0
blur.Enabled = false
blur.Parent = lighting

-- 创建基础动画函数
local function tween(obj, props)
    local tweenInfo = TweenInfo.new(ANIM_SPEED, EASE_IN_OUT, Enum.EasingDirection.InOut)
    local tween = tweenService:Create(obj, tweenInfo, props)
    tween:Play()
    return tween
end

function Fun:MakeDraggable(frame, dragTarget)
    dragTarget = dragTarget or frame
    local dragging, startPos, startPosFrame
    frame.InputBegan:Connect(function(input)
        if input.UserInputType == Enum.UserInputType.MouseButton1 then
            dragging = true
            startPos = input.Position
            startPosFrame = dragTarget.Position
            -- 拖动时轻微缩小反馈（修复UDim2运算错误）
            local newSize = UDim2.new(
                dragTarget.Size.X.Scale,
                dragTarget.Size.X.Offset * 0.98,
                dragTarget.Size.Y.Scale,
                dragTarget.Size.Y.Offset * 0.98
            )
            tween(dragTarget, {Size = newSize})
        end
    end)
    uis.InputChanged:Connect(function(input)
        if dragging and input.UserInputType == Enum.UserInputType.MouseMovement then
            local delta = input.Position - startPos
            dragTarget.Position = UDim2.new(
                startPosFrame.X.Scale, startPosFrame.X.Offset + delta.X,
                startPosFrame.Y.Scale, startPosFrame.Y.Offset + delta.Y
            )
        end
    end)
    uis.InputEnded:Connect(function(input)
        if input.UserInputType == Enum.UserInputType.MouseButton1 and dragging then
            dragging = false
            -- 结束拖动时恢复大小（修复UDim2运算错误）
            local restoreSize = UDim2.new(
                dragTarget.Size.X.Scale,
                dragTarget.Size.X.Offset / 0.98,
                dragTarget.Size.Y.Scale,
                dragTarget.Size.Y.Offset / 0.98
            )
            tween(dragTarget, {Size = restoreSize})
        end
    end)
end

function Fun.Create(title)
    -- 主容器
    local ui = Instance.new("ScreenGui")
    ui.Name = "AnimatedUI"
    ui.Parent = game.CoreGui
    ui.ZIndexBehavior = Enum.ZIndexBehavior.Sibling
    ui.ResetOnSpawn = false
    ui.Enabled = false

    -- 背景阴影
    local shadow = Instance.new("ImageLabel")
    shadow.Name = "Shadow"
    shadow.Parent = ui
    shadow.BackgroundTransparency = 1
    shadow.Position = UDim2.new(0.35, 0, 0.2, 0)
    shadow.Size = UDim2.new(0, 500, 0, 400)
    shadow.Image = "rbxassetid://6105530152"
    shadow.ImageColor3 = Color3.fromRGB(10, 10, 10)
    shadow.ImageTransparency = 0.8
    shadow.ScaleType = Enum.ScaleType.Slice
    shadow.SliceCenter = Rect.new(10, 10, 10, 10)

    -- 主窗口
    local mainFrame = Instance.new("Frame")
    mainFrame.Name = "MainFrame"
    mainFrame.Parent = shadow
    mainFrame.BackgroundColor3 = Color3.fromRGB(35, 35, 42)
    mainFrame.Position = UDim2.new(0.02, 0, 0.02, 0)
    mainFrame.Size = UDim2.new(0, 470, 0, 370)
    mainFrame.BackgroundTransparency = 1
    mainFrame.ClipsDescendants = true

    local mainCorner = Instance.new("UICorner")
    mainCorner.CornerRadius = UDim.new(0, 8)
    mainCorner.Parent = mainFrame

    -- 侧边栏
    local sidebar = Instance.new("Frame")
    sidebar.Name = "Sidebar"
    sidebar.Parent = mainFrame
    sidebar.BackgroundColor3 = Color3.fromRGB(28, 28, 34)
    sidebar.Size = UDim2.new(0, 150, 1, 0)

    local sidebarCorner = Instance.new("UICorner")
    sidebarCorner.CornerRadius = UDim.new(0, 8)
    sidebarCorner.Parent = sidebar

    -- 标题
    local titleLabel = Instance.new("TextLabel")
    titleLabel.Name = "Title"
    titleLabel.Parent = sidebar
    titleLabel.BackgroundTransparency = 1
    titleLabel.Position = UDim2.new(0, 15, 0, 15)
    titleLabel.Size = UDim2.new(0, 120, 0, 30)
    titleLabel.Font = Enum.Font.GothamBold
    titleLabel.Text = title
    titleLabel.TextColor3 = Color3.fromRGB(160, 120, 200)
    titleLabel.TextSize = 18
    titleLabel.TextXAlignment = Enum.TextXAlignment.Left

    -- 标签容器
    local tabsContainer = Instance.new("Frame")
    tabsContainer.Name = "Tabs"
    tabsContainer.Parent = sidebar
    tabsContainer.BackgroundTransparency = 1
    tabsContainer.Position = UDim2.new(0, 0, 0, 60)
    tabsContainer.Size = UDim2.new(1, 0, 1, -60)

    local tabsLayout = Instance.new("UIListLayout")
    tabsLayout.Parent = tabsContainer
    tabsLayout.SortOrder = Enum.SortOrder.LayoutOrder
    tabsLayout.Padding = UDim.new(0, 2)

    -- 内容容器
    local contentContainer = Instance.new("Frame")
    contentContainer.Name = "Content"
    contentContainer.Parent = mainFrame
    contentContainer.BackgroundTransparency = 1
    contentContainer.Position = UDim2.new(0, 160, 0, 10)
    contentContainer.Size = UDim2.new(1, -170, 1, -20)

    local pages = Instance.new("Folder")
    pages.Name = "Pages"
    pages.Parent = contentContainer

    -- 窗口显示/隐藏动画逻辑
    local function showWindow()
        ui.Enabled = true
        blur.Enabled = true
        tween(blur, {Size = 12})
        tween(shadow, {ImageTransparency = 0.5})
        tween(mainFrame, {
            BackgroundTransparency = 0,
            Position = UDim2.new(0.02, 0, 0.02, 0),
            Size = UDim2.new(0, 470, 0, 370)
        })
    end

    local function hideWindow()
        tween(blur, {Size = 0})
        tween(shadow, {ImageTransparency = 0.8})
        tween(mainFrame, {
            BackgroundTransparency = 1,
            Position = UDim2.new(0.02, 0, 0.05, 0),
            Size = UDim2.new(0, 470 * 0.95, 0, 370 * 0.95)
        })
        task.wait(ANIM_SPEED)
        ui.Enabled = false
        blur.Enabled = false
    end

    -- 绑定Insert键显示/隐藏
    uis.InputBegan:Connect(function(input)
        if input.KeyCode == Enum.KeyCode.Insert then
            if ui.Enabled then
                hideWindow()
            else
                showWindow()
            end
        end
    end)

    -- 标签系统
    local tabSystem = {}
    function tabSystem:Tab(tabName)
        -- 标签按钮
        local tabBtn = Instance.new("TextButton")
        tabBtn.Name = "Tab_" .. tabName
        tabBtn.Parent = tabsContainer
        tabBtn.BackgroundColor3 = Color3.fromRGB(35, 35, 42)
        tabBtn.BackgroundTransparency = 1
        tabBtn.Size = UDim2.new(1, -10, 0, 35)
        tabBtn.Position = UDim2.new(0, 5, 0, 0)
        tabBtn.Font = Enum.Font.Gotham
        tabBtn.Text = tabName
        tabBtn.TextColor3 = Color3.fromRGB(160, 160, 170)
        tabBtn.TextSize = 15
        tabBtn.TextXAlignment = Enum.TextXAlignment.Left

        -- 标签下划线（默认隐藏）
        local tabUnderline = Instance.new("Frame")
        tabUnderline.Name = "Underline"
        tabUnderline.Parent = tabBtn
        tabUnderline.BackgroundColor3 = Color3.fromRGB(160, 120, 200)
        tabUnderline.Size = UDim2.new(0, 0, 0, 2)
        tabUnderline.Position = UDim2.new(0, 0, 1, -2)

        -- 内容页
        local page = Instance.new("ScrollingFrame")
        page.Name = "Page_" .. tabName
        page.Parent = pages
        page.Active = true
        page.BackgroundTransparency = 1
        page.BorderSizePixel = 0
        page.Size = UDim2.new(1, 0, 1, 0)
        page.ScrollBarThickness = 5
        page.ScrollBarImageColor3 = Color3.fromRGB(50, 50, 60)
        page.Visible = false

        local pageLayout = Instance.new("UIListLayout")
        pageLayout.Parent = page
        pageLayout.SortOrder = Enum.SortOrder.LayoutOrder
        pageLayout.Padding = UDim.new(0, 8)

        -- 页面大小更新
        local function updatePageSize()
            local contentSize = pageLayout.AbsoluteContentSize
            tween(page, {CanvasSize = UDim2.new(0, contentSize.X, 0, contentSize.Y + 10)})
        end
        page.ChildAdded:Connect(updatePageSize)
        page.ChildRemoved:Connect(updatePageSize)

        -- 标签点击动画
        tabBtn.MouseButton1Click:Connect(function()
            -- 重置所有标签状态
            for _, btn in ipairs(tabsContainer:GetChildren()) do
                if btn:IsA("TextButton") then
                    tween(btn, {TextColor3 = Color3.fromRGB(160, 160, 170)})
                    tween(btn.Underline, {Size = UDim2.new(0, 0, 0, 2)})
                end
            end
            -- 激活当前标签
            tween(tabBtn, {TextColor3 = Color3.fromRGB(160, 120, 200)})
            tween(tabUnderline, {Size = UDim2.new(1, 0, 0, 2)})
            
            -- 隐藏所有页面
            for _, p in ipairs(pages:GetChildren()) do
                if p:IsA("ScrollingFrame") then
                    tween(p, {BackgroundTransparency = 1})
                    task.wait(ANIM_SPEED * 0.3)
                    p.Visible = false
                end
            end
            -- 显示当前页面
            page.Visible = true
            tween(page, {BackgroundTransparency = 0})
        end)

        -- 标签悬停动画
        tabBtn.MouseEnter:Connect(function()
            if tabBtn.TextColor3 ~= Color3.fromRGB(160, 120, 200) then
                tween(tabBtn, {TextColor3 = Color3.fromRGB(200, 200, 210)})
            end
        end)
        tabBtn.MouseLeave:Connect(function()
            if tabBtn.TextColor3 ~= Color3.fromRGB(160, 120, 200) then
                tween(tabBtn, {TextColor3 = Color3.fromRGB(160, 160, 170)})
            end
        end)

        -- 分区系统
        local sectionSystem = {}
        function sectionSystem:Section(sectionName)
            -- 分区容器
            local section = Instance.new("Frame")
            section.Name = "Section_" .. sectionName
            section.Parent = page
            section.BackgroundColor3 = Color3.fromRGB(40, 40, 48)
            section.Size = UDim2.new(1, 0, 0, 40)
            section.ClipsDescendants = true

            local sectionCorner = Instance.new("UICorner")
            sectionCorner.CornerRadius = UDim.new(0, 6)
            sectionCorner.Parent = section

            -- 分区标题栏
            local sectionHeader = Instance.new("Frame")
            sectionHeader.Name = "Header"
            sectionHeader.Parent = section
            sectionHeader.BackgroundColor3 = Color3.fromRGB(40, 40, 48)
            sectionHeader.Size = UDim2.new(1, 0, 0, 40)

            -- 标题文本
            local sectionTitle = Instance.new("TextLabel")
            sectionTitle.Name = "Title"
            sectionTitle.Parent = sectionHeader
            sectionTitle.BackgroundTransparency = 1
            sectionTitle.Position = UDim2.new(0, 15, 0, 0)
            sectionTitle.Size = UDim2.new(1, -40, 1, 0)
            sectionTitle.Font = Enum.Font.Gotham
            sectionTitle.Text = sectionName
            sectionTitle.TextColor3 = Color3.fromRGB(180, 180, 190)
            sectionTitle.TextSize = 14
            sectionTitle.TextXAlignment = Enum.TextXAlignment.Left

            -- 展开/折叠按钮
            local toggleBtn = Instance.new("ImageButton")
            toggleBtn.Name = "Toggle"
            toggleBtn.Parent = sectionHeader
            toggleBtn.BackgroundTransparency = 1
            toggleBtn.Position = UDim2.new(1, -35, 0, 10)
            toggleBtn.Size = UDim2.new(0, 20, 0, 20)
            toggleBtn.Image = "rbxassetid://3926305904"
            toggleBtn.ImageColor3 = Color3.fromRGB(160, 160, 170)
            toggleBtn.ImageRectOffset = Vector2.new(404, 284)
            toggleBtn.ImageRectSize = Vector2.new(36, 36)

            -- 内容容器
            local contentFrame = Instance.new("Frame")
            contentFrame.Name = "Content"
            contentFrame.Parent = section
            contentFrame.BackgroundTransparency = 1
            contentFrame.Position = UDim2.new(0, 0, 0, 40)
            contentFrame.Size = UDim2.new(1, 0, 0, 0)

            local contentLayout = Instance.new("UIListLayout")
            contentLayout.Parent = contentFrame
            contentLayout.SortOrder = Enum.SortOrder.LayoutOrder
            contentLayout.Padding = UDim.new(0, 6)

            -- 展开/折叠状态
            local isExpanded = false
            local function updateSectionSize()
                local targetHeight = isExpanded and (40 + contentLayout.AbsoluteContentSize.Y + 10) or 40
                tween(section, {Size = UDim2.new(1, 0, 0, targetHeight)})
                tween(contentFrame, {Size = UDim2.new(1, 0, 0, isExpanded and (contentLayout.AbsoluteContentSize.Y + 10) or 0)})
            end

            -- 展开/折叠动画
            toggleBtn.MouseButton1Click:Connect(function()
                isExpanded = not isExpanded
                tween(toggleBtn, {Rotation = isExpanded and 180 or 0})
                tween(sectionTitle, {TextColor3 = isExpanded and Color3.fromRGB(160, 120, 200) or Color3.fromRGB(180, 180, 190)})
                updateSectionSize()
                task.wait(ANIM_SPEED)
                updatePageSize()
            end)

            -- 内容大小更新
            contentFrame.ChildAdded:Connect(function()
                task.wait()
                if isExpanded then
                    updateSectionSize()
                    updatePageSize()
                end
            end)

            -- 控件系统
            local widgetSystem = {}

            -- 按钮控件
            function widgetSystem:Button(text, callback)
                local btn = Instance.new("TextButton")
                btn.Name = "Button_" .. text
                btn.Parent = contentFrame
                btn.BackgroundColor3 = Color3.fromRGB(160, 120, 200)
                btn.Position = UDim2.new(0, 10, 0, 0)
                btn.Size = UDim2.new(1, -20, 0, 35)
                btn.AutoButtonColor = false
                btn.Font = Enum.Font.Gotham
                btn.Text = text
                btn.TextColor3 = Color3.fromRGB(255, 255, 255)
                btn.TextSize = 14

                local btnCorner = Instance.new("UICorner")
                btnCorner.CornerRadius = UDim.new(0, 4)
                btnCorner.Parent = btn

                -- 悬停动画
                btn.MouseEnter:Connect(function()
                    tween(btn, {
                        BackgroundColor3 = Color3.fromRGB(180, 140, 220),
                        Size = UDim2.new(1, -18, 0, 37)
                    })
                end)
                btn.MouseLeave:Connect(function()
                    tween(btn, {
                        BackgroundColor3 = Color3.fromRGB(160, 120, 200),
                        Size = UDim2.new(1, -20, 0, 35)
                    })
                end)
                -- 点击动画
                btn.MouseButton1Down:Connect(function()
                    tween(btn, {
                        BackgroundColor3 = Color3.fromRGB(140, 100, 180),
                        Size = UDim2.new(1, -22, 0, 33)
                    })
                end)
                btn.MouseButton1Up:Connect(function()
                    tween(btn, {
                        BackgroundColor3 = Color3.fromRGB(180, 140, 220),
                        Size = UDim2.new(1, -18, 0, 37)
                    })
                end)
                -- 点击回调
                btn.MouseButton1Click:Connect(callback)
            end

            -- 开关控件（修复点击事件错误）
            function widgetSystem:Toggle(text, callback)
                local isOn = false
                local frame = Instance.new("Frame")
                frame.Name = "Toggle_" .. text
                frame.Parent = contentFrame
                frame.BackgroundTransparency = 1
                frame.Position = UDim2.new(0, 10, 0, 0)
                frame.Size = UDim2.new(1, -20, 0, 30)

                local layout = Instance.new("UIListLayout")
                layout.Parent = frame
                layout.FillDirection = Enum.FillDirection.Horizontal
                layout.VerticalAlignment = Enum.VerticalAlignment.Center
                layout.Padding = UDim.new(0, 10)

                -- 开关背景（改为TextButton支持点击）
                local toggleBg = Instance.new("TextButton")
                toggleBg.Name = "Background"
                toggleBg.Parent = frame
                toggleBg.BackgroundColor3 = Color3.fromRGB(60, 60, 70)
                toggleBg.Size = UDim2.new(0, 40, 0, 20)
                toggleBg.AutoButtonColor = false
                toggleBg.Text = ""

                local bgCorner = Instance.new("UICorner")
                bgCorner.CornerRadius = UDim.new(0, 10)
                bgCorner.Parent = toggleBg

                -- 开关滑块
                local toggleKnob = Instance.new("Frame")
                toggleKnob.Name = "Knob"
                toggleKnob.Parent = toggleBg
                toggleKnob.BackgroundColor3 = Color3.fromRGB(200, 200, 200)
                toggleKnob.Position = UDim2.new(0, 2, 0, 2)
                toggleKnob.Size = UDim2.new(0, 16, 0, 16)

                local knobCorner = Instance.new("UICorner")
                knobCorner.CornerRadius = UDim.new(0, 8)
                knobCorner.Parent = toggleKnob

                -- 开关文本
                local toggleText = Instance.new("TextLabel")
                toggleText.Name = "Text"
                toggleText.Parent = frame
                toggleText.BackgroundTransparency = 1
                toggleText.Size = UDim2.new(1, -50, 0, 20)
                toggleText.Font = Enum.Font.Gotham
                toggleText.Text = text
                toggleText.TextColor3 = Color3.fromRGB(180, 180, 190)
                toggleText.TextSize = 14
                toggleText.TextXAlignment = Enum.TextXAlignment.Left

                -- 切换动画
                local function toggle()
                    isOn = not isOn
                    callback(isOn)
                    tween(toggleBg, {BackgroundColor3 = isOn and Color3.fromRGB(160, 120, 200) or Color3.fromRGB(60, 60, 70)})
                    tween(toggleKnob, {
                        Position = isOn and UDim2.new(0, 22, 0, 2) or UDim2.new(0, 2, 0, 2),
                        BackgroundColor3 = isOn and Color3.fromRGB(255, 255, 255) or Color3.fromRGB(200, 200, 200)
                    })
                    tween(toggleText, {TextColor3 = isOn and Color3.fromRGB(160, 120, 200) or Color3.fromRGB(180, 180, 190)})
                end

                toggleBg.MouseButton1Click:Connect(toggle)
                toggleText.MouseButton1Click:Connect(toggle)
            end

            -- 下拉菜单
            function widgetSystem:Dropdown(text, options, callback)
                local frame = Instance.new("Frame")
                frame.Name = "Dropdown_" .. text
                frame.Parent = contentFrame
                frame.BackgroundColor3 = Color3.fromRGB(45, 45, 53)
                frame.Position = UDim2.new(0, 10, 0, 0)
                frame.Size = UDim2.new(1, -20, 0, 35)

                local frameCorner = Instance.new("UICorner")
                frameCorner.CornerRadius = UDim.new(0, 4)
                frameCorner.Parent = frame

                -- 标题
                local dropText = Instance.new("TextLabel")
                dropText.Name = "Text"
                dropText.Parent = frame
                dropText.BackgroundTransparency = 1
                dropText.Position = UDim2.new(0, 15, 0, 0)
                dropText.Size = UDim2.new(1, -50, 1, 0)
                dropText.Font = Enum.Font.Gotham
                dropText.Text = text
                dropText.TextColor3 = Color3.fromRGB(180, 180, 190)
                dropText.TextSize = 14
                dropText.TextXAlignment = Enum.TextXAlignment.Left

                -- 下拉按钮
                local dropBtn = Instance.new("ImageButton")
                dropBtn.Name = "Toggle"
                dropBtn.Parent = frame
                dropBtn.BackgroundTransparency = 1
                dropBtn.Position = UDim2.new(1, -40, 0, 7.5)
                dropBtn.Size = UDim2.new(0, 20, 0, 20)
                dropBtn.Image = "rbxassetid://3926305904"
                dropBtn.ImageColor3 = Color3.fromRGB(160, 160, 170)
                dropBtn.ImageRectOffset = Vector2.new(404, 284)
                dropBtn.ImageRectSize = Vector2.new(36, 36)

                -- 选项容器
                local optionsContainer = Instance.new("Frame")
                optionsContainer.Name = "Options"
                optionsContainer.Parent = frame
                optionsContainer.BackgroundColor3 = Color3.fromRGB(45, 45, 53)
                optionsContainer.Position = UDim2.new(0, 0, 1, 1)
                optionsContainer.Size = UDim2.new(1, 0, 0, 0)
                optionsContainer.ClipsDescendants = true

                local optionsLayout = Instance.new("UIListLayout")
                optionsLayout.Parent = optionsContainer
                optionsLayout.SortOrder = Enum.SortOrder.LayoutOrder

                local optionsCorner = Instance.new("UICorner")
                optionsCorner.CornerRadius = UDim.new(0, 4)
                optionsCorner.Parent = optionsContainer

                -- 创建选项
                local optionHeight = 30
                for i, opt in ipairs(options) do
                    local option = Instance.new("TextButton")
                    option.Name = "Option_" .. opt
                    option.Parent = optionsContainer
                    option.BackgroundColor3 = Color3.fromRGB(50, 50, 58)
                    option.Size = UDim2.new(1, 0, 0, optionHeight)
                    option.AutoButtonColor = false
                    option.Font = Enum.Font.Gotham
                    option.Text = opt
                    option.TextColor3 = Color3.fromRGB(180, 180, 190)
                    option.TextSize = 13
                    option.TextXAlignment = Enum.TextXAlignment.Left
                    option.TextYAlignment = Enum.TextYAlignment.Center

                    -- 选项悬停
                    option.MouseEnter:Connect(function()
                        tween(option, {
                            BackgroundColor3 = Color3.fromRGB(60, 60, 70),
                            TextColor3 = Color3.fromRGB(255, 255, 255)
                        })
                    end)
                    option.MouseLeave:Connect(function()
                        tween(option, {
                            BackgroundColor3 = Color3.fromRGB(50, 50, 58),
                            TextColor3 = Color3.fromRGB(180, 180, 190)
                        })
                    end)

                    -- 选项点击
                    option.MouseButton1Click:Connect(function()
                        dropText.Text = opt
                        callback(opt)
                        -- 收起菜单
                        tween(dropBtn, {Rotation = 0})
                        tween(frame, {Size = UDim2.new(1, -20, 0, 35)})
                        tween(optionsContainer, {Size = UDim2.new(1, 0, 0, 0)})
                        isExpanded = false
                        updateSectionSize()
                        updatePageSize()
                    end)
                end

                -- 展开/收起状态
                local isExpanded = false
                dropBtn.MouseButton1Click:Connect(function()
                    isExpanded = not isExpanded
                    local targetHeight = isExpanded and (35 + #options * optionHeight) or 35
                    tween(dropBtn, {Rotation = isExpanded and 180 or 0})
                    tween(frame, {Size = UDim2.new(1, -20, 0, targetHeight)})
                    tween(optionsContainer, {Size = UDim2.new(1, 0, 0, isExpanded and (#options * optionHeight) or 0)})
                    updateSectionSize()
                    updatePageSize()
                end)

                -- 悬停效果
                frame.MouseEnter:Connect(function()
                    tween(frame, {BackgroundColor3 = Color3.fromRGB(50, 50, 58)})
                end)
                frame.MouseLeave:Connect(function()
                    if not isExpanded then
                        tween(frame, {BackgroundColor3 = Color3.fromRGB(45, 45, 53)})
                    end
                end)
            end

            -- 滑块控件
            function widgetSystem:Slider(text, min, max, callback)
                local frame = Instance.new("Frame")
                frame.Name = "Slider_" .. text
                frame.Parent = contentFrame
                frame.BackgroundTransparency = 1
                frame.Position = UDim2.new(0, 10, 0, 0)
                frame.Size = UDim2.new(1, -20, 0, 50)

                -- 标题
                local sliderText = Instance.new("TextLabel")
                sliderText.Name = "Text"
                sliderText.Parent = frame
                sliderText.BackgroundTransparency = 1
                sliderText.Position = UDim2.new(0, 0, 0, 0)
                sliderText.Size = UDim2.new(1, 0, 0, 20)
                sliderText.Font = Enum.Font.Gotham
                sliderText.Text = text
                sliderText.TextColor3 = Color3.fromRGB(180, 180, 190)
                sliderText.TextSize = 14
                sliderText.TextXAlignment = Enum.TextXAlignment.Left

                -- 滑块容器
                local sliderContainer = Instance.new("Frame")
                sliderContainer.Name = "Container"
                sliderContainer.Parent = frame
                sliderContainer.BackgroundColor3 = Color3.fromRGB(60, 60, 70)
                sliderContainer.Position = UDim2.new(0, 0, 0, 25)
                sliderContainer.Size = UDim2.new(1, 0, 0, 6)

                local sliderCorner = Instance.new("UICorner")
                sliderCorner.CornerRadius = UDim.new(0, 3)
                sliderCorner.Parent = sliderContainer

                -- 滑块填充
                local sliderFill = Instance.new("Frame")
                sliderFill.Name = "Fill"
                sliderFill.Parent = sliderContainer
                sliderFill.BackgroundColor3 = Color3.fromRGB(160, 120, 200)
                sliderFill.Size = UDim2.new(0, 0, 1, 0)

                local fillCorner = Instance.new("UICorner")
                fillCorner.CornerRadius = UDim.new(0, 3)
                fillCorner.Parent = sliderFill

                -- 滑块按钮
                local sliderBtn = Instance.new("Frame")
                sliderBtn.Name = "Button"
                sliderBtn.Parent = sliderContainer
                sliderBtn.BackgroundColor3 = Color3.fromRGB(255, 255, 255)
                sliderBtn.Position = UDim2.new(0, -6, 0, -6)
                sliderBtn.Size = UDim2.new(0, 18, 0, 18)

                local btnCorner = Instance.new("UICorner")
                btnCorner.CornerRadius = UDim.new(0, 9)
                btnCorner.Parent = sliderBtn

                -- 数值显示
                local valueLabel = Instance.new("TextLabel")
                valueLabel.Name = "Value"
                valueLabel.Parent = frame
                valueLabel.BackgroundTransparency = 1
                valueLabel.Position = UDim2.new(1, 0, 0, 25)
                valueLabel.Size = UDim2.new(0, 50, 0, 20)
                valueLabel.Font = Enum.Font.Gotham
                valueLabel.Text = tostring(min)
                valueLabel.TextColor3 = Color3.fromRGB(160, 120, 200)
                valueLabel.TextSize = 13
                valueLabel.TextXAlignment = Enum.TextXAlignment.Right

                -- 滑块逻辑
                local value = min
                local function updateSlider(pos)
                    local ratio = math.clamp(pos / sliderContainer.AbsoluteSize.X, 0, 1)
                    value = math.floor(ratio * (max - min) + min)
                    tween(sliderFill, {Size = UDim2.new(ratio, 0, 1, 0)})
                    tween(sliderBtn, {Position = UDim2.new(ratio, -6, 0, -6)})
                    valueLabel.Text = tostring(value)
                    callback(value)
                end

                -- 拖动逻辑
                local isDragging = false
                sliderContainer.InputBegan:Connect(function(input)
                    if input.UserInputType == Enum.UserInputType.MouseButton1 then
                        isDragging = true
                        tween(sliderBtn, {Size = UDim2.new(0, 22, 0, 22)})
                        updateSlider(input.Position.X - sliderContainer.AbsolutePosition.X)
                    end
                end)

                uis.InputChanged:Connect(function(input)
                    if isDragging and input.UserInputType == Enum.UserInputType.MouseMovement then
                        updateSlider(input.Position.X - sliderContainer.AbsolutePosition.X)
                    end
                end)

                uis.InputEnded:Connect(function(input)
                    if input.UserInputType == Enum.UserInputType.MouseButton1 and isDragging then
                        isDragging = false
                        tween(sliderBtn, {Size = UDim2.new(0, 18, 0, 18)})
                    end
                end)
            end

            -- 文本标签
            function widgetSystem:Label(text)
                local label = Instance.new("TextLabel")
                label.Name = "Label"
                label.Parent = contentFrame
                label.BackgroundTransparency = 1
                label.Position = UDim2.new(0, 10, 0, 0)
                label.Size = UDim2.new(1, -20, 0, 25)
                label.Font = Enum.Font.Gotham
                label.Text = text
                label.TextColor3 = Color3.fromRGB(150, 150, 160)
                label.TextSize = 13
                label.TextXAlignment = Enum.TextXAlignment.Left
                label.TextWrapped = true
            end

            -- 快捷键绑定
            function widgetSystem:KeyBind(text, defaultKey, callback)
                local currentKey = defaultKey.Name
                local frame = Instance.new("Frame")
                frame.Name = "KeyBind_" .. text
                frame.Parent = contentFrame
                frame.BackgroundTransparency = 1
                frame.Position = UDim2.new(0, 10, 0, 0)
                frame.Size = UDim2.new(1, -20, 0, 35)

                local layout = Instance.new("UIListLayout")
                layout.Parent = frame
                layout.FillDirection = Enum.FillDirection.Horizontal
                layout.VerticalAlignment = Enum.VerticalAlignment.Center
                layout.Padding = UDim.new(0, 10)

                -- 文本
                local bindText = Instance.new("TextLabel")
                bindText.Name = "Text"
                bindText.Parent = frame
                bindText.BackgroundTransparency = 1
                bindText.Size = UDim2.new(1, -120, 0, 25)
                bindText.Font = Enum.Font.Gotham
                bindText.Text = text
                bindText.TextColor3 = Color3.fromRGB(180, 180, 190)
                bindText.TextSize = 14
                bindText.TextXAlignment = Enum.TextXAlignment.Left

                -- 按键显示
                local keyBtn = Instance.new("TextButton")
                keyBtn.Name = "Key"
                keyBtn.Parent = frame
                keyBtn.BackgroundColor3 = Color3.fromRGB(45, 45, 53)
                keyBtn.Size = UDim2.new(0, 100, 0, 30)
                keyBtn.AutoButtonColor = false
                keyBtn.Font = Enum.Font.Gotham
                keyBtn.Text = currentKey
                keyBtn.TextColor3 = Color3.fromRGB(200, 200, 210)
                keyBtn.TextSize = 13

                local keyCorner = Instance.new("UICorner")
                keyCorner.CornerRadius = UDim.new(0, 4)
                keyCorner.Parent = keyBtn

                -- 绑定逻辑
                keyBtn.MouseButton1Click:Connect(function()
                    keyBtn.Text = "..."
                    keyBtn.TextColor3 = Color3.fromRGB(255, 180, 100)
                    local input = uis.InputBegan:Wait()
                    if input.KeyCode ~= Enum.KeyCode.Unknown then
                        currentKey = input.KeyCode.Name
                        keyBtn.Text = currentKey
                        keyBtn.TextColor3 = Color3.fromRGB(200, 200, 210)
                    else
                        keyBtn.Text = currentKey
                        keyBtn.TextColor3 = Color3.fromRGB(200, 200, 210)
                    end
                end)

                -- 按键触发
                uis.InputBegan:Connect(function(input, isGui)
                    if not isGui and input.KeyCode.Name == currentKey then
                        callback()
                        -- 触发反馈动画
                        tween(keyBtn, {BackgroundColor3 = Color3.fromRGB(60, 60, 70)})
                        task.wait(ANIM_SPEED * 0.5)
                        tween(keyBtn, {BackgroundColor3 = Color3.fromRGB(45, 45, 53)})
                    end
                end)

                -- 悬停效果
                keyBtn.MouseEnter:Connect(function()
                    tween(keyBtn, {BackgroundColor3 = Color3.fromRGB(55, 55, 63)})
                end)
                keyBtn.MouseLeave:Connect(function()
                    tween(keyBtn, {BackgroundColor3 = Color3.fromRGB(45, 45, 53)})
                end)
            end

            -- 文本输入框
            function widgetSystem:TextBox(placeholder, callback)
                local box = Instance.new("TextBox")
                box.Name = "TextBox"
                box.Parent = contentFrame
                box.BackgroundColor3 = Color3.fromRGB(45, 45, 53)
                box.Position = UDim2.new(0, 10, 0, 0)
                box.Size = UDim2.new(1, -20, 0, 35)
                box.ClearTextOnFocus = false
                box.Font = Enum.Font.Gotham
                box.PlaceholderText = placeholder
                box.PlaceholderColor3 = Color3.fromRGB(120, 120, 130)
                box.Text = ""
                box.TextColor3 = Color3.fromRGB(200, 200, 210)
                box.TextSize = 14
                box.TextXAlignment = Enum.TextXAlignment.Left

                local boxCorner = Instance.new("UICorner")
                boxCorner.CornerRadius = UDim.new(0, 4)
                boxCorner.Parent = box

                -- 聚焦/失焦动画
                box.Focused:Connect(function()
                    tween(box, {BackgroundColor3 = Color3.fromRGB(50, 50, 58)})
                end)
                box.FocusLost:Connect(function(enterPressed)
                    tween(box, {BackgroundColor3 = Color3.fromRGB(45, 45, 53)})
                    if enterPressed then
                        callback(box.Text)
                        -- 提交反馈
                        tween(box, {Size = UDim2.new(1, -24, 0, 33)})
                        task.wait(ANIM_SPEED * 0.3)
                        tween(box, {Size = UDim2.new(1, -20, 0, 35)})
                    end
                end)
            end

            return widgetSystem
        end
        return sectionSystem
    end

    -- 初始化窗口状态（隐藏）
    mainFrame.Position = UDim2.new(0.02, 0, 0.05, 0)
    mainFrame.Size = UDim2.new(0, 470 * 0.95, 0, 370 * 0.95)
    
    -- 启用拖拽
    Fun:MakeDraggable(titleLabel, shadow)

    return tabSystem
end

return Fun